﻿using System;
using System.Collections.Generic;
using System.Text;
using net.veekee.common.data;
using net.veekee.common;

namespace net.veekee.logprocessor.plugin.rules
{
    public class RuleEnvironment
    {
        private static RuleEnvironment Instance = null;
        public static RuleEnvironment GetInstance()
        {
            if (RuleEnvironment.Instance == null)
                RuleEnvironment.Instance = new RuleEnvironment();
            return RuleEnvironment.Instance;
        }

        public FieldManager Fields = null;

        public RuleEnvironment()
        {
            this.Fields = new FieldManager();
        }

        public void Reload(String container)
        {
            if(container == null)
                return;
            this.Fields.Load(container);
        }

        public void Reload(String[] envcoll)
        {
            foreach (String env in envcoll)
            {
                String[] envprops = env.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
                if (envprops.Length == 1)
                {
                    this.Fields.Set<String>(envprops[0], "");
                }
                else
                {
                    this.Fields.Set<String>(envprops[0], envprops[1]);
                }
            }
        }
    }
}
